home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / sysutils.int < prev    next >
Encoding:
Text File  |  1998-02-09  |  79.5 KB  |  1,973 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Delphi Runtime Library                          }
  5. {       System Utilities Unit                           }
  6. {                                                       }
  7. {       Copyright (C) 1995,98 Borland International     }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit SysUtils;
  12.  
  13. {$H+}
  14.  
  15. interface
  16.  
  17. uses Windows, SysConst;
  18.  
  19. const
  20.  
  21. { File open modes }
  22.  
  23.   fmOpenRead       = $0000;
  24.   fmOpenWrite      = $0001;
  25.   fmOpenReadWrite  = $0002;
  26.   fmShareCompat    = $0000;
  27.   fmShareExclusive = $0010;
  28.   fmShareDenyWrite = $0020;
  29.   fmShareDenyRead  = $0030;
  30.   fmShareDenyNone  = $0040;
  31.  
  32. { File attribute constants }
  33.  
  34.   faReadOnly  = $00000001;
  35.   faHidden    = $00000002;
  36.   faSysFile   = $00000004;
  37.   faVolumeID  = $00000008;
  38.   faDirectory = $00000010;
  39.   faArchive   = $00000020;
  40.   faAnyFile   = $0000003F;
  41.  
  42. { File mode magic numbers }
  43.  
  44.   fmClosed = $D7B0;
  45.   fmInput  = $D7B1;
  46.   fmOutput = $D7B2;
  47.   fmInOut  = $D7B3;
  48.  
  49. { Seconds and milliseconds per day }
  50.  
  51.   SecsPerDay = 24 * 60 * 60;
  52.   MSecsPerDay = SecsPerDay * 1000;
  53.  
  54. { Days between 1/1/0001 and 12/31/1899 }
  55.  
  56.   DateDelta = 693594;
  57.  
  58. type
  59.  
  60. { Standard Character set type }
  61.  
  62.   TSysCharSet = set of Char;
  63.  
  64. { Type conversion records }
  65.  
  66.   WordRec = packed record
  67.     Lo, Hi: Byte;
  68.   end;
  69.  
  70.   LongRec = packed record
  71.     Lo, Hi: Word;
  72.   end;
  73.  
  74.   TMethod = record
  75.     Code, Data: Pointer;
  76.   end;
  77.  
  78. { General arrays }
  79.  
  80.   PByteArray = ^TByteArray;
  81.   TByteArray = array[0..32767] of Byte;
  82.  
  83.   PWordArray = ^TWordArray;
  84.   TWordArray = array[0..16383] of Word;
  85.  
  86. { Generic procedure pointer }
  87.  
  88.   TProcedure = procedure;
  89.  
  90. { Generic filename type }
  91.  
  92.   TFileName = type string;
  93.  
  94. { Search record used by FindFirst, FindNext, and FindClose }
  95.  
  96.   TSearchRec = record
  97.     Time: Integer;
  98.     Size: Integer;
  99.     Attr: Integer;
  100.     Name: TFileName;
  101.     ExcludeAttr: Integer;
  102.     FindHandle: THandle;
  103.     FindData: TWin32FindData;
  104.   end;
  105.  
  106. { Typed-file and untyped-file record }
  107.  
  108.   TFileRec = record
  109.     Handle: Integer;
  110.     Mode: Integer;
  111.     RecSize: Cardinal;
  112.     Private: array[1..28] of Byte;
  113.     UserData: array[1..32] of Byte;
  114.     Name: array[0..259] of Char;
  115.   end;
  116.  
  117. { Text file record structure used for Text files }
  118.  
  119.   PTextBuf = ^TTextBuf;
  120.   TTextBuf = array[0..127] of Char;
  121.   TTextRec = record
  122.     Handle: Integer;
  123.     Mode: Integer;
  124.     BufSize: Cardinal;
  125.     BufPos: Cardinal;
  126.     BufEnd: Cardinal;
  127.     BufPtr: PChar;
  128.     OpenFunc: Pointer;
  129.     InOutFunc: Pointer;
  130.     FlushFunc: Pointer;
  131.     CloseFunc: Pointer;
  132.     UserData: array[1..32] of Byte;
  133.     Name: array[0..259] of Char;
  134.     Buffer: TTextBuf;
  135.   end;
  136.  
  137. { FloatToText, FloatToTextFmt, TextToFloat, and FloatToDecimal type codes }
  138.  
  139.   TFloatValue = (fvExtended, fvCurrency);
  140.  
  141. { FloatToText format codes }
  142.  
  143.   TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
  144.  
  145. { FloatToDecimal result record }
  146.  
  147.   TFloatRec = packed record
  148.     Exponent: Smallint;
  149.     Negative: Boolean;
  150.     Digits: array[0..20] of Char;
  151.   end;
  152.  
  153. { Date and time record }
  154.  
  155.   TTimeStamp = record
  156.     Time: Integer;      { Number of milliseconds since midnight }
  157.     Date: Integer;      { One plus number of days since 1/1/0001 }
  158.   end;
  159.  
  160. { MultiByte Character Set (MBCS) byte type }
  161.   TMbcsByteType = (mbSingleByte, mbLeadByte, mbTrailByte);
  162.  
  163. { System Locale information record }
  164.   TSysLocale = packed record
  165.     DefaultLCID: LCID;
  166.     PriLangID: LANGID;
  167.     SubLangID: LANGID;
  168.     FarEast: Boolean;
  169.   end;
  170.  
  171. { Exceptions }
  172.  
  173.   Exception = class(TObject)
  174.   public
  175.     constructor Create(const Msg: string);
  176.     constructor CreateFmt(const Msg: string; const Args: array of const);
  177.     constructor CreateRes(Ident: Integer; Dummy: Extended = 0);
  178.     constructor CreateResFmt(Ident: Integer; const Args: array of const);
  179.     constructor CreateHelp(const Msg: string; AHelpContext: Integer);
  180.     constructor CreateFmtHelp(const Msg: string; const Args: array of const;
  181.       AHelpContext: Integer);
  182.     constructor CreateResHelp(Ident: Integer; AHelpContext: Integer);
  183.     constructor CreateResFmtHelp(Ident: Integer; const Args: array of const;
  184.       AHelpContext: Integer);
  185.     property HelpContext: Integer;
  186.     property Message: string;
  187.   end;
  188.  
  189.   ExceptClass = class of Exception;
  190.  
  191.   EAbort = class(Exception);
  192.  
  193.   EOutOfMemory = class(Exception)
  194.   public
  195.     destructor Destroy; override;
  196.     procedure FreeInstance; override;
  197.   end;
  198.  
  199.   EInOutError = class(Exception)
  200.   public
  201.     ErrorCode: Integer;
  202.   end;
  203.  
  204.   EExternal = class(Exception)
  205.   public
  206.     ExceptionRecord: PExceptionRecord;
  207.   end;
  208.  
  209.   EExternalException = class(EExternal);
  210.  
  211.   EIntError = class(EExternal);
  212.   EDivByZero = class(EIntError);
  213.   ERangeError = class(EIntError);
  214.   EIntOverflow = class(EIntError);
  215.  
  216.   EMathError = class(EExternal);
  217.   EInvalidOp = class(EMathError);
  218.   EZeroDivide = class(EMathError);
  219.   EOverflow = class(EMathError);
  220.   EUnderflow = class(EMathError);
  221.  
  222.   EInvalidPointer = class(Exception);
  223.  
  224.   EInvalidCast = class(Exception);
  225.  
  226.   EConvertError = class(Exception);
  227.  
  228.   EAccessViolation = class(EExternal);
  229.   EPrivilege = class(EExternal);
  230.   EStackOverflow = class(EExternal);
  231.   EControlC = class(EExternal);
  232.  
  233.   EVariantError = class(Exception);
  234.  
  235.   EPropReadOnly = class(Exception);
  236.   EPropWriteOnly = class(Exception);
  237.  
  238.   EAssertionFailed = class(Exception);
  239.  
  240.   EAbstractError = class(Exception);
  241.  
  242.   EIntfCastError = class(Exception);
  243.  
  244.   EInvalidContainer = class(Exception);
  245.   EInvalidInsert = class(Exception);
  246.  
  247.   EPackageError = class(Exception);
  248.  
  249.   EWin32Error = class(Exception)
  250.   public
  251.     ErrorCode: DWORD;
  252.   end;
  253.  
  254. var
  255.  
  256. { Empty string and null string pointer. These constants are provided for
  257.   backwards compatibility only.  }
  258.  
  259.   EmptyStr: string = '';
  260.   NullStr: PString = @EmptyStr;
  261.  
  262. { Win32 platform identifier.  This will be one of the following values:
  263.  
  264.     VER_PLATFORM_WIN32s
  265.     VER_PLATFORM_WIN32_WINDOWS
  266.     VER_PLATFORM_WIN32_NT
  267.  
  268.   See WINDOWS.PAS for the numerical values. }
  269.  
  270.   Win32Platform: Integer = 0;
  271.  
  272. { Win32 OS version information -
  273.  
  274.   see TOSVersionInfo.dwMajorVersion/dwMinorVersion/dwBuildNumber }
  275.  
  276.   Win32MajorVersion: Integer = 0;
  277.   Win32MinorVersion: Integer = 0;
  278.   Win32BuildNumber: Integer = 0;
  279.  
  280. { Win32 OS extra version info string -
  281.  
  282.   see TOSVersionInfo.szCSDVersion }
  283.  
  284.   Win32CSDVersion: string = '';
  285.  
  286. { Currency and date/time formatting options
  287.  
  288.   The initial values of these variables are fetched from the system registry
  289.   using the GetLocaleInfo function in the Win32 API. The description of each
  290.   variable specifies the LOCALE_XXXX constant used to fetch the initial
  291.   value.
  292.  
  293.   CurrencyString - Defines the currency symbol used in floating-point to
  294.   decimal conversions. The initial value is fetched from LOCALE_SCURRENCY.
  295.  
  296.   CurrencyFormat - Defines the currency symbol placement and separation
  297.   used in floating-point to decimal conversions. Possible values are:
  298.  
  299.     0 = '$1'
  300.     1 = '1$'
  301.     2 = '$ 1'
  302.     3 = '1 $'
  303.  
  304.   The initial value is fetched from LOCALE_ICURRENCY.
  305.  
  306.   NegCurrFormat - Defines the currency format for used in floating-point to
  307.   decimal conversions of negative numbers. Possible values are:
  308.  
  309.     0 = '($1)'      4 = '(1$)'      8 = '-1 $'      12 = '$ -1'
  310.     1 = '-$1'       5 = '-1$'       9 = '-$ 1'      13 = '1- $'
  311.     2 = '$-1'       6 = '1-$'      10 = '1 $-'      14 = '($ 1)'
  312.     3 = '$1-'       7 = '1$-'      11 = '$ 1-'      15 = '(1 $)'
  313.  
  314.   The initial value is fetched from LOCALE_INEGCURR.
  315.  
  316.   ThousandSeparator - The character used to separate thousands in numbers
  317.   with more than three digits to the left of the decimal separator. The
  318.   initial value is fetched from LOCALE_STHOUSAND.
  319.  
  320.   DecimalSeparator - The character used to separate the integer part from
  321.   the fractional part of a number. The initial value is fetched from
  322.   LOCALE_SDECIMAL.
  323.  
  324.   CurrencyDecimals - The number of digits to the right of the decimal point
  325.   in a currency amount. The initial value is fetched from LOCALE_ICURRDIGITS.
  326.  
  327.   DateSeparator - The character used to separate the year, month, and day
  328.   parts of a date value. The initial value is fetched from LOCATE_SDATE.
  329.  
  330.   ShortDateFormat - The format string used to convert a date value to a
  331.   short string suitable for editing. For a complete description of date and
  332.   time format strings, refer to the documentation for the FormatDate
  333.   function. The short date format should only use the date separator
  334.   character and the  m, mm, d, dd, yy, and yyyy format specifiers. The
  335.   initial value is fetched from LOCALE_SSHORTDATE.
  336.  
  337.   LongDateFormat - The format string used to convert a date value to a long
  338.   string suitable for display but not for editing. For a complete description
  339.   of date and time format strings, refer to the documentation for the
  340.   FormatDate function. The initial value is fetched from LOCALE_SLONGDATE.
  341.  
  342.   TimeSeparator - The character used to separate the hour, minute, and
  343.   second parts of a time value. The initial value is fetched from
  344.   LOCALE_STIME.
  345.  
  346.   TimeAMString - The suffix string used for time values between 00:00 and
  347.   11:59 in 12-hour clock format. The initial value is fetched from
  348.   LOCALE_S1159.
  349.  
  350.   TimePMString - The suffix string used for time values between 12:00 and
  351.   23:59 in 12-hour clock format. The initial value is fetched from
  352.   LOCALE_S2359.
  353.  
  354.   ShortTimeFormat - The format string used to convert a time value to a
  355.   short string with only hours and minutes. The default value is computed
  356.   from LOCALE_ITIME and LOCALE_ITLZERO.
  357.  
  358.   LongTimeFormat - The format string used to convert a time value to a long
  359.   string with hours, minutes, and seconds. The default value is computed
  360.   from LOCALE_ITIME and LOCALE_ITLZERO.
  361.  
  362.   ShortMonthNames - Array of strings containing short month names. The mmm
  363.   format specifier in a format string passed to FormatDate causes a short
  364.   month name to be substituted. The default values are fecthed from the
  365.   LOCALE_SABBREVMONTHNAME system locale entries.
  366.  
  367.   LongMonthNames - Array of strings containing long month names. The mmmm
  368.   format specifier in a format string passed to FormatDate causes a long
  369.   month name to be substituted. The default values are fecthed from the
  370.   LOCALE_SMONTHNAME system locale entries.
  371.  
  372.   ShortDayNames - Array of strings containing short day names. The ddd
  373.   format specifier in a format string passed to FormatDate causes a short
  374.   day name to be substituted. The default values are fecthed from the
  375.   LOCALE_SABBREVDAYNAME system locale entries.
  376.  
  377.   LongDayNames - Array of strings containing long day names. The dddd
  378.   format specifier in a format string passed to FormatDate causes a long
  379.   day name to be substituted. The default values are fecthed from the
  380.   LOCALE_SDAYNAME system locale entries. }
  381.  
  382. var
  383.   CurrencyString: string;
  384.   CurrencyFormat: Byte;
  385.   NegCurrFormat: Byte;
  386.   ThousandSeparator: Char;
  387.   DecimalSeparator: Char;
  388.   CurrencyDecimals: Byte;
  389.   DateSeparator: Char;
  390.   ShortDateFormat: string;
  391.   LongDateFormat: string;
  392.   TimeSeparator: Char;
  393.   TimeAMString: string;
  394.   TimePMString: string;
  395.   ShortTimeFormat: string;
  396.   LongTimeFormat: string;
  397.   ShortMonthNames: array[1..12] of string;
  398.   LongMonthNames: array[1..12] of string;
  399.   ShortDayNames: array[1..7] of string;
  400.   LongDayNames: array[1..7] of string;
  401.   SysLocale: TSysLocale;
  402.   EraNames: array[1..7] of string;
  403.   EraYearOffsets: array[1..7] of Integer;
  404.  
  405. { Memory management routines }
  406.  
  407. { AllocMem allocates a block of the given size on the heap. Each byte in
  408.   the allocated buffer is set to zero. To dispose the buffer, use the
  409.   FreeMem standard procedure. }
  410.  
  411. function AllocMem(Size: Cardinal): Pointer;
  412.  
  413. { Exit procedure handling }
  414.  
  415. { AddExitProc adds the given procedure to the run-time library's exit
  416.   procedure list. When an application terminates, its exit procedures are
  417.   executed in reverse order of definition, i.e. the last procedure passed
  418.   to AddExitProc is the first one to get executed upon termination. }
  419.  
  420. procedure AddExitProc(Proc: TProcedure);
  421.  
  422. { String handling routines }
  423.  
  424. { NewStr allocates a string on the heap. NewStr is provided for backwards
  425.   compatibility only. }
  426.  
  427. function NewStr(const S: string): PString;
  428.  
  429. { DisposeStr disposes a string pointer that was previously allocated using
  430.   NewStr. DisposeStr is provided for backwards compatibility only. }
  431.  
  432. procedure DisposeStr(P: PString);
  433.  
  434. { AssignStr assigns a new dynamically allocated string to the given string
  435.   pointer. AssignStr is provided for backwards compatibility only. }
  436.  
  437. procedure AssignStr(var P: PString; const S: string);
  438.  
  439. { AppendStr appends S to the end of Dest. AppendStr is provided for
  440.   backwards compatibility only. Use "Dest := Dest + S" instead. }
  441.  
  442. procedure AppendStr(var Dest: string; const S: string);
  443.  
  444. { UpperCase converts all ASCII characters in the given string to upper case.
  445.   The conversion affects only 7-bit ASCII characters between 'a' and 'z'. To
  446.   convert 8-bit international characters, use AnsiUpperCase. }
  447.  
  448. function UpperCase(const S: string): string;
  449.  
  450. { LowerCase converts all ASCII characters in the given string to lower case.
  451.   The conversion affects only 7-bit ASCII characters between 'A' and 'Z'. To
  452.   convert 8-bit international characters, use AnsiLowerCase. }
  453.  
  454. function LowerCase(const S: string): string;
  455.  
  456. { CompareStr compares S1 to S2, with case-sensitivity. The return value is
  457.   less than 0 if S1 < S2, 0 if S1 = S2, or greater than 0 if S1 > S2. The
  458.   compare operation is based on the 8-bit ordinal value of each character
  459.   and is not affected by the current Windows locale. }
  460.  
  461. function CompareStr(const S1, S2: string): Integer;
  462.  
  463. { CompareMem performs a binary compare of Length bytes of memory referenced
  464.   by P1 to that of P2.  CompareMem returns True if the memory referenced by
  465.   P1 is identical to that of P2. }
  466.  
  467. function CompareMem(P1, P2: Pointer; Length: Integer): Boolean; assembler;
  468.  
  469. { CompareText compares S1 to S2, without case-sensitivity. The return value
  470.   is the same as for CompareStr. The compare operation is based on the 8-bit
  471.   ordinal value of each character, after converting 'a'..'z' to 'A'..'Z',
  472.   and is not affected by the current Windows locale. }
  473.  
  474. function CompareText(const S1, S2: string): Integer;
  475.  
  476. { AnsiUpperCase converts all characters in the given string to upper case.
  477.   The conversion uses the current Windows locale. }
  478.  
  479. function AnsiUpperCase(const S: string): string;
  480.  
  481. { AnsiLowerCase converts all characters in the given string to lower case.
  482.   The conversion uses the current Windows locale. }
  483.  
  484. function AnsiLowerCase(const S: string): string;
  485.  
  486. { AnsiCompareStr compares S1 to S2, with case-sensitivity. The compare
  487.   operation is controlled by the current Windows locale. The return value
  488.   is the same as for CompareStr. }
  489.  
  490. function AnsiCompareStr(const S1, S2: string): Integer;
  491.  
  492. { AnsiCompareText compares S1 to S2, without case-sensitivity. The compare
  493.   operation is controlled by the current Windows locale. The return value
  494.   is the same as for CompareStr. }
  495.  
  496. function AnsiCompareText(const S1, S2: string): Integer;
  497.  
  498. { AnsiStrComp compares S1 to S2, with case-sensitivity. The compare
  499.   operation is controlled by the current Windows locale. The return value
  500.   is the same as for CompareStr. }
  501.  
  502. function AnsiStrComp(S1, S2: PChar): Integer;
  503.  
  504. { AnsiStrIComp compares S1 to S2, without case-sensitivity. The compare
  505.   operation is controlled by the current Windows locale. The return value
  506.   is the same as for CompareStr. }
  507.  
  508. function AnsiStrIComp(S1, S2: PChar): Integer;
  509.  
  510. { AnsiStrLComp compares S1 to S2, with case-sensitivity, up to a maximum
  511.   length of MaxLen bytes. The compare operation is controlled by the
  512.   current Windows locale. The return value is the same as for CompareStr. }
  513.  
  514. function AnsiStrLComp(S1, S2: PChar; MaxLen: Cardinal): Integer;
  515.  
  516. { AnsiStrLIComp compares S1 to S2, without case-sensitivity, up to a maximum
  517.   length of MaxLen bytes. The compare operation is controlled by the
  518.   current Windows locale. The return value is the same as for CompareStr. }
  519.  
  520. function AnsiStrLIComp(S1, S2: PChar; MaxLen: Cardinal): Integer;
  521.  
  522. { AnsiStrLower converts all characters in the given string to lower case.
  523.   The conversion uses the current Windows locale. }
  524.  
  525. function AnsiStrLower(Str: PChar): PChar;
  526.  
  527. { AnsiStrUpper converts all characters in the given string to upper case.
  528.   The conversion uses the current Windows locale. }
  529.  
  530. function AnsiStrUpper(Str: PChar): PChar;
  531.  
  532. { AnsiLastChar returns a pointer to the last full character in the string.
  533.   This function supports multibyte characters  }
  534.  
  535. function AnsiLastChar(const S: string): PChar;
  536.  
  537. { AnsiStrLastChar returns a pointer to the last full character in the string.
  538.   This function supports multibyte characters.  }
  539.  
  540. function AnsiStrLastChar(P: PChar): PChar;
  541.  
  542. { Trim trims leading and trailing spaces and control characters from the
  543.   given string. }
  544.  
  545. function Trim(const S: string): string;
  546.  
  547. { TrimLeft trims leading spaces and control characters from the given
  548.   string. }
  549.  
  550. function TrimLeft(const S: string): string;
  551.  
  552. { TrimRight trims trailing spaces and control characters from the given
  553.   string. }
  554.  
  555. function TrimRight(const S: string): string;
  556.  
  557. { QuotedStr returns the given string as a quoted string. A single quote
  558.   character is inserted at the beginning and the end of the string, and
  559.   for each single quote character in the string, another one is added. }
  560.  
  561. function QuotedStr(const S: string): string;
  562.  
  563. { AnsiQuotedStr returns the given string as a quoted string, using the
  564.   provided Quote character.  A Quote character is inserted at the beginning
  565.   and end of thestring, and each Quote character in the string is doubled.
  566.   This function supports multibyte character strings (MBCS). }
  567.  
  568. function AnsiQuotedStr(const S: string; Quote: Char): string;
  569.  
  570. { AnsiExtractQuotedStr removes the Quote characters from the beginning and end
  571.   of a quoted string, and reduces pairs of Quote characters within the quoted
  572.   string to a single character. If the first character in Src is not the Quote
  573.   character, the function returns an empty string.  The function copies
  574.   characters from the Src to the result string until the second solitary
  575.   Quote character or the first null character in Src. The Src parameter is
  576.   updated to point to the first character following the quoted string.  If
  577.   the Src string does not contain a matching end Quote character, the Src
  578.   parameter is updated to point to the terminating null character in Src.
  579.   This function supports multibyte character strings (MBCS).  }
  580.  
  581. function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;
  582.  
  583. { AdjustLineBreaks adjusts all line breaks in the given string to be true
  584.   CR/LF sequences. The function changes any CR characters not followed by
  585.   a LF and any LF characters not preceded by a CR into CR/LF pairs. }
  586.  
  587. function AdjustLineBreaks(const S: string): string;
  588.  
  589. { IsValidIdent returns true if the given string is a valid identifier. An
  590.   identifier is defined as a character from the set ['A'..'Z', 'a'..'z', '_']
  591.   followed by zero or more characters from the set ['A'..'Z', 'a'..'z',
  592.   '0..'9', '_']. }
  593.  
  594. function IsValidIdent(const Ident: string): Boolean;
  595.  
  596. { IntToStr converts the given value to its decimal string representation. }
  597.  
  598. function IntToStr(Value: Integer): string;
  599.  
  600. { IntToHex converts the given value to a hexadecimal string representation
  601.   with the minimum number of digits specified. }
  602.  
  603. function IntToHex(Value: Integer; Digits: Integer): string;
  604.  
  605. { StrToInt converts the given string to an integer value. If the string
  606.   doesn't contain a valid value, an EConvertError exception is raised. }
  607.  
  608. function StrToInt(const S: string): Integer;
  609.  
  610. { StrToIntDef converts the given string to an integer value. If the string
  611.   doesn't contain a valid value, the value given by Default is returned. }
  612.  
  613. function StrToIntDef(const S: string; Default: Integer): Integer;
  614.  
  615. { LoadStr loads the string resource given by Ident from the application's
  616.   executable file. If the string resource does not exist, an empty string
  617.   is returned. }
  618.  
  619. function LoadStr(Ident: Integer): string;
  620.  
  621. { LoadStr loads the string resource given by Ident from the application's
  622.   executable file, and uses it as the format string in a call to the
  623.   Format function with the given arguments. }
  624.  
  625. function FmtLoadStr(Ident: Integer; const Args: array of const): string;
  626.  
  627. { File management routines }
  628.  
  629. { FileOpen opens the specified file using the specified access mode. The
  630.   access mode value is constructed by OR-ing one of the fmOpenXXXX constants
  631.   with one of the fmShareXXXX constants. If the return value is positive,
  632.   the function was successful and the value is the file handle of the opened
  633.   file. A return value of -1 indicates that an error occurred. }
  634.  
  635. function FileOpen(const FileName: string; Mode: Integer): Integer;
  636.  
  637. { FileCreate creates a new file by the specified name. If the return value
  638.   is positive, the function was successful and the value is the file handle
  639.   of the new file. A return value of -1 indicates that an error occurred. }
  640.  
  641. function FileCreate(const FileName: string): Integer;
  642.  
  643. { FileRead reads Count bytes from the file given by Handle into the buffer
  644.   specified by Buffer. The return value is the number of bytes actually
  645.   read; it is less than Count if the end of the file was reached. The return
  646.   value is -1 if an error occurred. }
  647.  
  648. function FileRead(Handle: Integer; var Buffer; Count: Integer): Integer;
  649.  
  650. { FileWrite writes Count bytes to the file given by Handle from the buffer
  651.   specified by Buffer. The return value is the number of bytes actually
  652.   written, or -1 if an error occurred. }
  653.  
  654. function FileWrite(Handle: Integer; const Buffer; Count: Integer): Integer;
  655.  
  656. { FileSeek changes the current position of the file given by Handle to be
  657.   Offset bytes relative to the point given by Origin. Origin = 0 means that
  658.   Offset is relative to the beginning of the file, Origin = 1 means that
  659.   Offset is relative to the current position, and Origin = 2 means that
  660.   Offset is relative to the end of the file. The return value is the new
  661.   current position, relative to the beginning of the file, or -1 if an error
  662.   occurred. }
  663.  
  664. function FileSeek(Handle, Offset, Origin: Integer): Integer;
  665.  
  666. { FileClose closes the specified file. }
  667.  
  668. procedure FileClose(Handle: Integer);
  669.  
  670. { FileAge returns the date-and-time stamp of the specified file. The return
  671.   value can be converted to a TDateTime value using the FileDateToDateTime
  672.   function. The return value is -1 if the file does not exist. }
  673.  
  674. function FileAge(const FileName: string): Integer;
  675.  
  676. { FileExists returns a boolean value that indicates whether the specified
  677.   file exists. }
  678.  
  679. function FileExists(const FileName: string): Boolean;
  680.  
  681. { FindFirst searches the directory given by Path for the first entry that
  682.   matches the filename given by Path and the attributes given by Attr. The
  683.   result is returned in the search record given by SearchRec. The return
  684.   value is zero if the function was successful. Otherwise the return value
  685.   is a Windows error code. FindFirst is typically used in conjunction with
  686.   FindNext and FindClose as follows:
  687.  
  688.     Result := FindFirst(Path, Attr, SearchRec);
  689.     while Result = 0 do
  690.     begin
  691.       ProcessSearchRec(SearchRec);
  692.       Result := FindNext(SearchRec);
  693.     end;
  694.     FindClose(SearchRec);
  695.  
  696.   where ProcessSearchRec represents user-defined code that processes the
  697.   information in a search record. }
  698.  
  699. function FindFirst(const Path: string; Attr: Integer;
  700.   var F: TSearchRec): Integer;
  701.  
  702. { FindNext returs the next entry that matches the name and attributes
  703.   specified in a previous call to FindFirst. The search record must be one
  704.   that was passed to FindFirst. The return value is zero if the function was
  705.   successful. Otherwise the return value is a Windows error code. }
  706.  
  707. function FindNext(var F: TSearchRec): Integer;
  708.  
  709. { FindClose terminates a FindFirst/FindNext sequence. FindClose does nothing
  710.   in the 16-bit version of Windows, but is required in the 32-bit version,
  711.   so for maximum portability every FindFirst/FindNext sequence should end
  712.   with a call to FindClose. }
  713.  
  714. procedure FindClose(var F: TSearchRec);
  715.  
  716. { FileGetDate returns the DOS date-and-time stamp of the file given by
  717.   Handle. The return value is -1 if the handle is invalid. The
  718.   FileDateToDateTime function can be used to convert the returned value to
  719.   a TDateTime value. }
  720.  
  721. function FileGetDate(Handle: Integer): Integer;
  722.  
  723. { FileSetDate sets the DOS date-and-time stamp of the file given by Handle
  724.   to the value given by Age. The DateTimeToFileDate function can be used to
  725.   convert a TDateTime value to a DOS date-and-time stamp. The return value
  726.   is zero if the function was successful. Otherwise the return value is a
  727.   Windows error code. }
  728.  
  729. function FileSetDate(Handle: Integer; Age: Integer): Integer;
  730.  
  731. { FileGetAttr returns the file attributes of the file given by FileName. The
  732.   attributes can be examined by AND-ing with the faXXXX constants defined
  733.   above. A return value of -1 indicates that an error occurred. }
  734.  
  735. function FileGetAttr(const FileName: string): Integer;
  736.  
  737. { FileSetAttr sets the file attributes of the file given by FileName to the
  738.   value given by Attr. The attribute value is formed by OR-ing the
  739.   appropriate faXXXX constants. The return value is zero if the function was
  740.   successful. Otherwise the return value is a Windows error code. }
  741.  
  742. function FileSetAttr(const FileName: string; Attr: Integer): Integer;
  743.  
  744. { DeleteFile deletes the file given by FileName. The return value is True if
  745.   the file was successfully deleted, or False if an error occurred. }
  746.  
  747. function DeleteFile(const FileName: string): Boolean;
  748.  
  749. { RenameFile renames the file given by OldName to the name given by NewName.
  750.   The return value is True if the file was successfully renamed, or False if
  751.   an error occurred. }
  752.  
  753. function RenameFile(const OldName, NewName: string): Boolean;
  754.  
  755. { ChangeFileExt changes the extension of a filename. FileName specifies a
  756.   filename with or without an extension, and Extension specifies the new
  757.   extension for the filename. The new extension can be a an empty string or
  758.   a period followed by up to three characters. }
  759.  
  760. function ChangeFileExt(const FileName, Extension: string): string;
  761.  
  762. { ExtractFilePath extracts the drive and directory parts of the given
  763.   filename. The resulting string is the leftmost characters of FileName,
  764.   up to and including the colon or backslash that separates the path
  765.   information from the name and extension. The resulting string is empty
  766.   if FileName contains no drive and directory parts. }
  767.  
  768. function ExtractFilePath(const FileName: string): string;
  769.  
  770. { ExtractFileDir extracts the drive and directory parts of the given
  771.   filename. The resulting string is a directory name suitable for passing
  772.   to SetCurrentDir, CreateDir, etc. The resulting string is empty if
  773.   FileName contains no drive and directory parts. }
  774.  
  775. function ExtractFileDir(const FileName: string): string;
  776.  
  777. { ExtractFileDrive extracts the drive part of the given filename.  For
  778.   filenames with drive letters, the resulting string is '<drive>:'.
  779.   For filenames with a UNC path, the resulting string is in the form
  780.   '\\<servername>\<sharename>'.  If the given path contains neither
  781.   style of filename, the result is an empty string. }
  782.  
  783. function ExtractFileDrive(const FileName: string): string;
  784.  
  785. { ExtractFileName extracts the name and extension parts of the given
  786.   filename. The resulting string is the leftmost characters of FileName,
  787.   starting with the first character after the colon or backslash that
  788.   separates the path information from the name and extension. The resulting
  789.   string is equal to FileName if FileName contains no drive and directory
  790.   parts. }
  791.  
  792. function ExtractFileName(const FileName: string): string;
  793.  
  794. { ExtractFileExt extracts the extension part of the given filename. The
  795.   resulting string includes the period character that separates the name
  796.   and extension parts. The resulting string is empty if the given filename
  797.   has no extension. }
  798.  
  799. function ExtractFileExt(const FileName: string): string;
  800.  
  801. { ExpandFileName expands the given filename to a fully qualified filename.
  802.   The resulting string consists of a drive letter, a colon, a root relative
  803.   directory path, and a filename. Embedded '.' and '..' directory references
  804.   are removed. }
  805.  
  806. function ExpandFileName(const FileName: string): string;
  807.  
  808. { ExpandUNCFileName expands the given filename to a fully qualified filename.
  809.   This function is the same as ExpandFileName except that it will return the
  810.   drive portion of the filename in the format '\\<servername>\<sharename> if
  811.   that drive is actually a network resource instead of a local resource.
  812.   Like ExpandFileName, embedded '.' and '..' directory references are
  813.   removed. }
  814.  
  815. function ExpandUNCFileName(const FileName: string): string;
  816.  
  817. { ExtractRelativePath will return a file path name relative to the given
  818.   BaseName.  It strips the common path dirs and adds '..\' for each level
  819.   up from the BaseName path. }
  820.  
  821. function ExtractRelativePath(const BaseName, DestName: string): string;
  822.  
  823. { ExtractShortPathName will convert the given filename to the short form
  824.   by calling the GetShortPathName API.  Will return an empty string if
  825.   the file or directory specified does not exist }
  826.  
  827. function ExtractShortPathName(const FileName: string): string;
  828.  
  829. { FileSearch searches for the file given by Name in the list of directories
  830.   given by DirList. The directory paths in DirList must be separated by
  831.   semicolons. The search always starts with the current directory of the
  832.   current drive. The returned value is a concatenation of one of the
  833.   directory paths and the filename, or an empty string if the file could not
  834.   be located. }
  835.  
  836. function FileSearch(const Name, DirList: string): string;
  837.  
  838. { DiskFree returns the number of free bytes on the specified drive number,
  839.   where 0 = Current, 1 = A, 2 = B, etc. DiskFree returns -1 if the drive
  840.   number is invalid. }
  841.  
  842. function DiskFree(Drive: Byte): Integer;
  843.  
  844. { DiskSize returns the size in bytes of the specified drive number, where
  845.   0 = Current, 1 = A, 2 = B, etc. DiskSize returns -1 if the drive number
  846.   is invalid. }
  847.  
  848. function DiskSize(Drive: Byte): Integer;
  849.  
  850. { FileDateToDateTime converts a DOS date-and-time value to a TDateTime
  851.   value. The FileAge, FileGetDate, and FileSetDate routines operate on DOS
  852.   date-and-time values, and the Time field of a TSearchRec used by the
  853.   FindFirst and FindNext functions contains a DOS date-and-time value. }
  854.  
  855. function FileDateToDateTime(FileDate: Integer): TDateTime;
  856.  
  857. { DateTimeToFileDate converts a TDateTime value to a DOS date-and-time
  858.   value. The FileAge, FileGetDate, and FileSetDate routines operate on DOS
  859.   date-and-time values, and the Time field of a TSearchRec used by the
  860.   FindFirst and FindNext functions contains a DOS date-and-time value. }
  861.  
  862. function DateTimeToFileDate(DateTime: TDateTime): Integer;
  863.  
  864. { GetCurrentDir returns the current directory. }
  865.  
  866. function GetCurrentDir: string;
  867.  
  868. { SetCurrentDir sets the current directory. The return value is True if
  869.   the current directory was successfully changed, or False if an error
  870.   occurred. }
  871.  
  872. function SetCurrentDir(const Dir: string): Boolean;
  873.  
  874. { CreateDir creates a new directory. The return value is True if a new
  875.   directory was successfully created, or False if an error occurred. }
  876.  
  877. function CreateDir(const Dir: string): Boolean;
  878.  
  879. { RemoveDir deletes an existing empty directory. The return value is
  880.   True if the directory was successfully deleted, or False if an error
  881.   occurred. }
  882.  
  883. function RemoveDir(const Dir: string): Boolean;
  884.  
  885. { PChar routines }
  886.  
  887. { StrLen returns the number of characters in Str, not counting the null
  888.   terminator. }
  889.  
  890. function StrLen(Str: PChar): Cardinal;
  891.  
  892. { StrEnd returns a pointer to the null character that terminates Str. }
  893.  
  894. function StrEnd(Str: PChar): PChar;
  895.  
  896. { StrMove copies exactly Count characters from Source to Dest and returns
  897.   Dest. Source and Dest may overlap. }
  898.  
  899. function StrMove(Dest, Source: PChar; Count: Cardinal): PChar;
  900.  
  901. { StrCopy copies Source to Dest and returns Dest. }
  902.  
  903. function StrCopy(Dest, Source: PChar): PChar;
  904.  
  905. { StrECopy copies Source to Dest and returns StrEnd(Dest). }
  906.  
  907. function StrECopy(Dest, Source: PChar): PChar;
  908.  
  909. { StrLCopy copies at most MaxLen characters from Source to Dest and
  910.   returns Dest. }
  911.  
  912. function StrLCopy(Dest, Source: PChar; MaxLen: Cardinal): PChar;
  913.  
  914. { StrPCopy copies the Pascal style string Source into Dest and
  915.   returns Dest. }
  916.  
  917. function StrPCopy(Dest: PChar; const Source: string): PChar;
  918.  
  919. { StrPLCopy copies at most MaxLen characters from the Pascal style string
  920.   Source into Dest and returns Dest. }
  921.  
  922. function StrPLCopy(Dest: PChar; const Source: string;
  923.   MaxLen: Cardinal): PChar;
  924.  
  925. { StrCat appends a copy of Source to the end of Dest and returns Dest. }
  926.  
  927. function StrCat(Dest, Source: PChar): PChar;
  928.  
  929. { StrLCat appends at most MaxLen - StrLen(Dest) characters from Source to
  930.   the end of Dest, and returns Dest. }
  931.  
  932. function StrLCat(Dest, Source: PChar; MaxLen: Cardinal): PChar;
  933.  
  934. { StrComp compares Str1 to Str2. The return value is less than 0 if
  935.   Str1 < Str2, 0 if Str1 = Str2, or greater than 0 if Str1 > Str2. }
  936.  
  937. function StrComp(Str1, Str2: PChar): Integer;
  938.  
  939. { StrIComp compares Str1 to Str2, without case sensitivity. The return
  940.   value is the same as StrComp. }
  941.  
  942. function StrIComp(Str1, Str2: PChar): Integer;
  943.  
  944. { StrLComp compares Str1 to Str2, for a maximum length of MaxLen
  945.   characters. The return value is the same as StrComp. }
  946.  
  947. function StrLComp(Str1, Str2: PChar; MaxLen: Cardinal): Integer;
  948.  
  949. { StrLIComp compares Str1 to Str2, for a maximum length of MaxLen
  950.   characters, without case sensitivity. The return value is the same
  951.   as StrComp. }
  952.  
  953. function StrLIComp(Str1, Str2: PChar; MaxLen: Cardinal): Integer;
  954.  
  955. { StrScan returns a pointer to the first occurrence of Chr in Str. If Chr
  956.   does not occur in Str, StrScan returns NIL. The null terminator is
  957.   considered to be part of the string. }
  958.  
  959. function StrScan(Str: PChar; Chr: Char): PChar;
  960.  
  961. { StrRScan returns a pointer to the last occurrence of Chr in Str. If Chr
  962.   does not occur in Str, StrRScan returns NIL. The null terminator is
  963.   considered to be part of the string. }
  964.  
  965. function StrRScan(Str: PChar; Chr: Char): PChar;
  966.  
  967. { StrPos returns a pointer to the first occurrence of Str2 in Str1. If
  968.   Str2 does not occur in Str1, StrPos returns NIL. }
  969.  
  970. function StrPos(Str1, Str2: PChar): PChar;
  971.  
  972. { StrUpper converts Str to upper case and returns Str. }
  973.  
  974. function StrUpper(Str: PChar): PChar;
  975.  
  976. { StrLower converts Str to lower case and returns Str. }
  977.  
  978. function StrLower(Str: PChar): PChar;
  979.  
  980. { StrPas converts Str to a Pascal style string. This function is provided
  981.   for backwards compatibility only. To convert a null terminated string to
  982.   a Pascal style string, use a type cast or an assignment. }
  983.  
  984. function StrPas(Str: PChar): string;
  985.  
  986. { StrAlloc allocates a buffer of the given size on the heap. The size of
  987.   the allocated buffer is encoded in a four byte header that immediately
  988.   preceeds the buffer. To dispose the buffer, use StrDispose. }
  989.  
  990. function StrAlloc(Size: Cardinal): PChar;
  991.  
  992. { StrBufSize returns the allocated size of the given buffer, not including
  993.   the two byte header. }
  994.  
  995. function StrBufSize(Str: PChar): Cardinal;
  996.  
  997. { StrNew allocates a copy of Str on the heap. If Str is NIL, StrNew returns
  998.   NIL and doesn't allocate any heap space. Otherwise, StrNew makes a
  999.   duplicate of Str, obtaining space with a call to the StrAlloc function,
  1000.   and returns a pointer to the duplicated string. To dispose the string,
  1001.   use StrDispose. }
  1002.  
  1003. function StrNew(Str: PChar): PChar;
  1004.  
  1005. { StrDispose disposes a string that was previously allocated with StrAlloc
  1006.   or StrNew. If Str is NIL, StrDispose does nothing. }
  1007.  
  1008. procedure StrDispose(Str: PChar);
  1009.  
  1010. { String formatting routines }
  1011.  
  1012. { The Format routine formats the argument list given by the Args parameter
  1013.   using the format string given by the Format parameter.
  1014.  
  1015.   Format strings contain two types of objects--plain characters and format
  1016.   specifiers. Plain characters are copied verbatim to the resulting string.
  1017.   Format specifiers fetch arguments from the argument list and apply
  1018.   formatting to them.
  1019.  
  1020.   Format specifiers have the following form:
  1021.  
  1022.     "%" [index ":"] ["-"] [width] ["." prec] type
  1023.  
  1024.   A format specifier begins with a % character. After the % come the
  1025.   following, in this order:
  1026.  
  1027.   -  an optional argument index specifier, [index ":"]
  1028.   -  an optional left-justification indicator, ["-"]
  1029.   -  an optional width specifier, [width]
  1030.   -  an optional precision specifier, ["." prec]
  1031.   -  the conversion type character, type
  1032.  
  1033.   The following conversion characters are supported:
  1034.  
  1035.   d  Decimal. The argument must be an integer value. The value is converted
  1036.      to a string of decimal digits. If the format string contains a precision
  1037.      specifier, it indicates that the resulting string must contain at least
  1038.      the specified number of digits; if the value has less digits, the
  1039.      resulting string is left-padded with zeros.
  1040.  
  1041.   e  Scientific. The argument must be a floating-point value. The value is
  1042.      converted to a string of the form "-d.ddd...E+ddd". The resulting
  1043.      string starts with a minus sign if the number is negative, and one digit
  1044.      always precedes the decimal point. The total number of digits in the
  1045.      resulting string (including the one before the decimal point) is given
  1046.      by the precision specifer in the format string--a default precision of
  1047.      15 is assumed if no precision specifer is present. The "E" exponent
  1048.      character in the resulting string is always followed by a plus or minus
  1049.      sign and at least three digits.
  1050.  
  1051.   f  Fixed. The argument must be a floating-point value. The value is
  1052.      converted to a string of the form "-ddd.ddd...". The resulting string
  1053.      starts with a minus sign if the number is negative. The number of digits
  1054.      after the decimal point is given by the precision specifier in the
  1055.      format string--a default of 2 decimal digits is assumed if no precision
  1056.      specifier is present.
  1057.  
  1058.   g  General. The argument must be a floating-point value. The value is
  1059.      converted to the shortest possible decimal string using fixed or
  1060.      scientific format. The number of significant digits in the resulting
  1061.      string is given by the precision specifier in the format string--a
  1062.      default precision of 15 is assumed if no precision specifier is present.
  1063.      Trailing zeros are removed from the resulting string, and a decimal
  1064.      point appears only if necessary. The resulting string uses fixed point
  1065.      format if the number of digits to the left of the decimal point in the
  1066.      value is less than or equal to the specified precision, and if the
  1067.      value is greater than or equal to 0.00001. Otherwise the resulting
  1068.      string uses scientific format.
  1069.  
  1070.   n  Number. The argument must be a floating-point value. The value is
  1071.      converted to a string of the form "-d,ddd,ddd.ddd...". The "n" format
  1072.      corresponds to the "f" format, except that the resulting string
  1073.      contains thousand separators.
  1074.  
  1075.   m  Money. The argument must be a floating-point value. The value is
  1076.      converted to a string that represents a currency amount. The conversion
  1077.      is controlled by the CurrencyString, CurrencyFormat, NegCurrFormat,
  1078.      ThousandSeparator, DecimalSeparator, and CurrencyDecimals global
  1079.      variables, all of which are initialized from the Currency Format in
  1080.      the International section of the Windows Control Panel. If the format
  1081.      string contains a precision specifier, it overrides the value given
  1082.      by the CurrencyDecimals global variable.
  1083.  
  1084.   p  Pointer. The argument must be a pointer value. The value is converted
  1085.      to a string of the form "XXXX:YYYY" where XXXX and YYYY are the
  1086.      segment and offset parts of the pointer expressed as four hexadecimal
  1087.      digits.
  1088.  
  1089.   s  String. The argument must be a character, a string, or a PChar value.
  1090.      The string or character is inserted in place of the format specifier.
  1091.      The precision specifier, if present in the format string, specifies the
  1092.      maximum length of the resulting string. If the argument is a string
  1093.      that is longer than this maximum, the string is truncated.
  1094.  
  1095.   x  Hexadecimal. The argument must be an integer value. The value is
  1096.      converted to a string of hexadecimal digits. If the format string
  1097.      contains a precision specifier, it indicates that the resulting string
  1098.      must contain at least the specified number of digits; if the value has
  1099.      less digits, the resulting string is left-padded with zeros.
  1100.  
  1101.   Conversion characters may be specified in upper case as well as in lower
  1102.   case--both produce the same results.
  1103.  
  1104.   For all floating-point formats, the actual characters used as decimal and
  1105.   thousand separators are obtained from the DecimalSeparator and
  1106.   ThousandSeparator global variables.
  1107.  
  1108.   Index, width, and precision specifiers can be specified directly using
  1109.   decimal digit string (for example "%10d"), or indirectly using an asterisk
  1110.   charcater (for example "%*.*f"). When using an asterisk, the next argument
  1111.   in the argument list (which must be an integer value) becomes the value
  1112.   that is actually used. For example "Format('%*.*f', [8, 2, 123.456])" is
  1113.   the same as "Format('%8.2f', [123.456])".
  1114.  
  1115.   A width specifier sets the minimum field width for a conversion. If the
  1116.   resulting string is shorter than the minimum field width, it is padded
  1117.   with blanks to increase the field width. The default is to right-justify
  1118.   the result by adding blanks in front of the value, but if the format
  1119.   specifier contains a left-justification indicator (a "-" character
  1120.   preceding the width specifier), the result is left-justified by adding
  1121.   blanks after the value.
  1122.  
  1123.   An index specifier sets the current argument list index to the specified
  1124.   value. The index of the first argument in the argument list is 0. Using
  1125.   index specifiers, it is possible to format the same argument multiple
  1126.   times. For example "Format('%d %d %0:d %d', [10, 20])" produces the string
  1127.   '10 20 10 20'.
  1128.  
  1129.   The Format function can be combined with other formatting functions. For
  1130.   example
  1131.  
  1132.     S := Format('Your total was %s on %s', [
  1133.       FormatFloat('$#,##0.00;;zero', Total),
  1134.       FormatDateTime('mm/dd/yy', Date)]);
  1135.  
  1136.   which uses the FormatFloat and FormatDateTime functions to customize the
  1137.   format beyond what is possible with Format. }
  1138.  
  1139. function Format(const Format: string; const Args: array of const): string;
  1140.  
  1141. { FmtStr formats the argument list given by Args using the format string
  1142.   given by Format into the string variable given by Result. For further
  1143.   details, see the description of the Format function. }
  1144.  
  1145. procedure FmtStr(var Result: string; const Format: string;
  1146.   const Args: array of const);
  1147.  
  1148. { StrFmt formats the argument list given by Args using the format string
  1149.   given by Format into the buffer given by Buffer. It is up to the caller to
  1150.   ensure that Buffer is large enough for the resulting string. The returned
  1151.   value is Buffer. For further details, see the description of the Format
  1152.   function. }
  1153.  
  1154. function StrFmt(Buffer, Format: PChar; const Args: array of const): PChar;
  1155.  
  1156. { StrFmt formats the argument list given by Args using the format string
  1157.   given by Format into the buffer given by Buffer. The resulting string will
  1158.   contain no more than MaxLen characters, not including the null terminator.
  1159.   The returned value is Buffer. For further details, see the description of
  1160.   the Format function. }
  1161.  
  1162. function StrLFmt(Buffer: PChar; MaxLen: Cardinal; Format: PChar;
  1163.   const Args: array of const): PChar;
  1164.  
  1165. { FormatBuf formats the argument list given by Args using the format string
  1166.   given by Format and FmtLen into the buffer given by Buffer and BufLen.
  1167.   The Format parameter is a reference to a buffer containing FmtLen
  1168.   characters, and the Buffer parameter is a reference to a buffer of BufLen
  1169.   characters. The returned value is the number of characters actually stored
  1170.   in Buffer. The returned value is always less than or equal to BufLen. For
  1171.   further details, see the description of the Format function. }
  1172.  
  1173. function FormatBuf(var Buffer; BufLen: Cardinal; const Format;
  1174.   FmtLen: Cardinal; const Args: array of const): Cardinal;
  1175.  
  1176. { Floating point conversion routines }
  1177.  
  1178. { FloatToStr converts the floating-point value given by Value to its string
  1179.   representation. The conversion uses general number format with 15
  1180.   significant digits. For further details, see the description of the
  1181.   FloatToStrF function. }
  1182.  
  1183. function FloatToStr(Value: Extended): string;
  1184.  
  1185. { CurrToStr converts the currency value given by Value to its string
  1186.   representation. The conversion uses general number format. For further
  1187.   details, see the description of the CurrToStrF function. }
  1188.  
  1189. function CurrToStr(Value: Currency): string;
  1190.  
  1191. { FloatToStrF converts the floating-point value given by Value to its string
  1192.   representation. The Format parameter controls the format of the resulting
  1193.   string. The Precision parameter specifies the precision of the given value.
  1194.   It should be 7 or less for values of type Single, 15 or less for values of
  1195.   type Double, and 18 or less for values of type Extended. The meaning of the
  1196.   Digits parameter depends on the particular format selected.
  1197.  
  1198.   The possible values of the Format parameter, and the meaning of each, are
  1199.   described below.
  1200.  
  1201.   ffGeneral - General number format. The value is converted to the shortest
  1202.   possible decimal string using fixed or scientific format. Trailing zeros
  1203.   are removed from the resulting string, and a decimal point appears only
  1204.   if necessary. The resulting string uses fixed point format if the number
  1205.   of digits to the left of the decimal point in the value is less than or
  1206.   equal to the specified precision, and if the value is greater than or
  1207.   equal to 0.00001. Otherwise the resulting string uses scientific format,
  1208.   and the Digits parameter specifies the minimum number of digits in the
  1209.   exponent (between 0 and 4).
  1210.  
  1211.   ffExponent - Scientific format. The value is converted to a string of the
  1212.   form "-d.ddd...E+dddd". The resulting string starts with a minus sign if
  1213.   the number is negative, and one digit always precedes the decimal point.
  1214.   The total number of digits in the resulting string (including the one
  1215.   before the decimal point) is given by the Precision parameter. The "E"
  1216.   exponent character in the resulting string is always followed by a plus
  1217.   or minus sign and up to four digits. The Digits parameter specifies the
  1218.   minimum number of digits in the exponent (between 0 and 4).
  1219.  
  1220.   ffFixed - Fixed point format. The value is converted to a string of the
  1221.   form "-ddd.ddd...". The resulting string starts with a minus sign if the
  1222.   number is negative, and at least one digit always precedes the decimal
  1223.   point. The number of digits after the decimal point is given by the Digits
  1224.   parameter--it must be between 0 and 18. If the number of digits to the
  1225.   left of the decimal point is greater than the specified precision, the
  1226.   resulting value will use scientific format.
  1227.  
  1228.   ffNumber - Number format. The value is converted to a string of the form
  1229.   "-d,ddd,ddd.ddd...". The ffNumber format corresponds to the ffFixed format,
  1230.   except that the resulting string contains thousand separators.
  1231.  
  1232.   ffCurrency - Currency format. The value is converted to a string that
  1233.   represents a currency amount. The conversion is controlled by the
  1234.   CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator, and
  1235.   DecimalSeparator global variables, all of which are initialized from the
  1236.   Currency Format in the International section of the Windows Control Panel.
  1237.   The number of digits after the decimal point is given by the Digits
  1238.   parameter--it must be between 0 and 18.
  1239.  
  1240.   For all formats, the actual characters used as decimal and thousand
  1241.   separators are obtained from the DecimalSeparator and ThousandSeparator
  1242.   global variables.
  1243.  
  1244.   If the given value is a NAN (not-a-number), the resulting string is 'NAN'.
  1245.   If the given value is positive infinity, the resulting string is 'INF'. If
  1246.   the given value is negative infinity, the resulting string is '-INF'. }
  1247.  
  1248. function FloatToStrF(Value: Extended; Format: TFloatFormat;
  1249.   Precision, Digits: Integer): string;
  1250.  
  1251. { CurrToStrF converts the currency value given by Value to its string
  1252.   representation. A call to CurrToStrF corresponds to a call to
  1253.   FloatToStrF with an implied precision of 19 digits. }
  1254.  
  1255. function CurrToStrF(Value: Currency; Format: TFloatFormat;
  1256.   Digits: Integer): string;
  1257.  
  1258. { FloatToText converts the given floating-point value to its decimal
  1259.   representation using the specified format, precision, and digits. The
  1260.   Value parameter must be a variable of type Extended or Currency, as
  1261.   indicated by the ValueType parameter. The resulting string of characters
  1262.   is stored in the given buffer, and the returned value is the number of
  1263.   characters stored. The resulting string is not null-terminated. For
  1264.   further details, see the description of the FloatToStrF function. }
  1265.  
  1266. function FloatToText(Buffer: PChar; const Value; ValueType: TFloatValue;
  1267.   Format: TFloatFormat; Precision, Digits: Integer): Integer;
  1268.  
  1269. { FormatFloat formats the floating-point value given by Value using the
  1270.   format string given by Format. The following format specifiers are
  1271.   supported in the format string:
  1272.  
  1273.   0     Digit placeholder. If the value being formatted has a digit in the
  1274.         position where the '0' appears in the format string, then that digit
  1275.         is copied to the output string. Otherwise, a '0' is stored in that
  1276.         position in the output string.
  1277.  
  1278.   #     Digit placeholder. If the value being formatted has a digit in the
  1279.         position where the '#' appears in the format string, then that digit
  1280.         is copied to the output string. Otherwise, nothing is stored in that
  1281.         position in the output string.
  1282.  
  1283.   .     Decimal point. The first '.' character in the format string
  1284.         determines the location of the decimal separator in the formatted
  1285.         value; any additional '.' characters are ignored. The actual
  1286.         character used as a the decimal separator in the output string is
  1287.         determined by the DecimalSeparator global variable. The default value
  1288.         of DecimalSeparator is specified in the Number Format of the
  1289.         International section in the Windows Control Panel.
  1290.  
  1291.   ,     Thousand separator. If the format string contains one or more ','
  1292.         characters, the output will have thousand separators inserted between
  1293.         each group of three digits to the left of the decimal point. The
  1294.         placement and number of ',' characters in the format string does not
  1295.         affect the output, except to indicate that thousand separators are
  1296.         wanted. The actual character used as a the thousand separator in the
  1297.         output is determined by the ThousandSeparator global variable. The
  1298.         default value of ThousandSeparator is specified in the Number Format
  1299.         of the International section in the Windows Control Panel.
  1300.  
  1301.   E+    Scientific notation. If any of the strings 'E+', 'E-', 'e+', or 'e-'
  1302.   E-    are contained in the format string, the number is formatted using
  1303.   e+    scientific notation. A group of up to four '0' characters can
  1304.   e-    immediately follow the 'E+', 'E-', 'e+', or 'e-' to determine the
  1305.         minimum number of digits in the exponent. The 'E+' and 'e+' formats
  1306.         cause a plus sign to be output for positive exponents and a minus
  1307.         sign to be output for negative exponents. The 'E-' and 'e-' formats
  1308.         output a sign character only for negative exponents.
  1309.  
  1310.   'xx'  Characters enclosed in single or double quotes are output as-is, and
  1311.   "xx"  do not affect formatting.
  1312.  
  1313.   ;     Separates sections for positive, negative, and zero numbers in the
  1314.         format string.
  1315.  
  1316.   The locations of the leftmost '0' before the decimal point in the format
  1317.   string and the rightmost '0' after the decimal point in the format string
  1318.   determine the range of digits that are always present in the output string.
  1319.  
  1320.   The number being formatted is always rounded to as many decimal places as
  1321.   there are digit placeholders ('0' or '#') to the right of the decimal
  1322.   point. If the format string contains no decimal point, the value being
  1323.   formatted is rounded to the nearest whole number.
  1324.  
  1325.   If the number being formatted has more digits to the left of the decimal
  1326.   separator than there are digit placeholders to the left of the '.'
  1327.   character in the format string, the extra digits are output before the
  1328.   first digit placeholder.
  1329.  
  1330.   To allow different formats for positive, negative, and zero values, the
  1331.   format string can contain between one and three sections separated by
  1332.   semicolons.
  1333.  
  1334.   One section - The format string applies to all values.
  1335.  
  1336.   Two sections - The first section applies to positive values and zeros, and
  1337.   the second section applies to negative values.
  1338.  
  1339.   Three sections - The first section applies to positive values, the second
  1340.   applies to negative values, and the third applies to zeros.
  1341.  
  1342.   If the section for negative values or the section for zero values is empty,
  1343.   that is if there is nothing between the semicolons that delimit the
  1344.   section, the section for positive values is used instead.
  1345.  
  1346.   If the section for positive values is empty, or if the entire format string
  1347.   is empty, the value is formatted using general floating-point formatting
  1348.   with 15 significant digits, corresponding to a call to FloatToStrF with
  1349.   the ffGeneral format. General floating-point formatting is also used if
  1350.   the value has more than 18 digits to the left of the decimal point and
  1351.   the format string does not specify scientific notation.
  1352.  
  1353.   The table below shows some sample formats and the results produced when
  1354.   the formats are applied to different values:
  1355.  
  1356.   Format string          1234        -1234       0.5         0
  1357.   -----------------------------------------------------------------------
  1358.                          1234        -1234       0.5         0
  1359.   0                      1234        -1234       1           0
  1360.   0.00                   1234.00     -1234.00    0.50        0.00
  1361.   #.##                   1234        -1234       .5
  1362.   #,##0.00               1,234.00    -1,234.00   0.50        0.00
  1363.   #,##0.00;(#,##0.00)    1,234.00    (1,234.00)  0.50        0.00
  1364.   #,##0.00;;Zero         1,234.00    -1,234.00   0.50        Zero
  1365.   0.000E+00              1.234E+03   -1.234E+03  5.000E-01   0.000E+00
  1366.   #.###E-0               1.234E3     -1.234E3    5E-1        0E0
  1367.   ----------------------------------------------------------------------- }
  1368.  
  1369. function FormatFloat(const Format: string; Value: Extended): string;
  1370.  
  1371. { FormatCurr formats the currency value given by Value using the format
  1372.   string given by Format. For further details, see the description of the
  1373.   FormatFloat function. }
  1374.  
  1375. function FormatCurr(const Format: string; Value: Currency): string;
  1376.  
  1377. { FloatToTextFmt converts the given floating-point value to its decimal
  1378.   representation using the specified format. The Value parameter must be a
  1379.   variable of type Extended or Currency, as indicated by the ValueType
  1380.   parameter. The resulting string of characters is stored in the given
  1381.   buffer, and the returned value is the number of characters stored. The
  1382.   resulting string is not null-terminated. For further details, see the
  1383.   description of the FormatFloat function. }
  1384.  
  1385. function FloatToTextFmt(Buffer: PChar; const Value; ValueType: TFloatValue;
  1386.   Format: PChar): Integer;
  1387.  
  1388. { StrToFloat converts the given string to a floating-point value. The string
  1389.   must consist of an optional sign (+ or -), a string of digits with an
  1390.   optional decimal point, and an optional 'E' or 'e' followed by a signed
  1391.   integer. Leading and trailing blanks in the string are ignored. The
  1392.   DecimalSeparator global variable defines the character that must be used
  1393.   as a decimal point. Thousand separators and currency symbols are not
  1394.   allowed in the string. If the string doesn't contain a valid value, an
  1395.   EConvertError exception is raised. }
  1396.  
  1397. function StrToFloat(const S: string): Extended;
  1398.  
  1399. { StrToCurr converts the given string to a currency value. For further
  1400.   details, see the description of the StrToFloat function. }
  1401.  
  1402. function StrToCurr(const S: string): Currency;
  1403.  
  1404. { TextToFloat converts the null-terminated string given by Buffer to a
  1405.   floating-point value which is returned in the variable given by Value.
  1406.   The Value parameter must be a variable of type Extended or Currency, as
  1407.   indicated by the ValueType parameter. The return value is True if the
  1408.   conversion was successful, or False if the string is not a valid
  1409.   floating-point value. For further details, see the description of the
  1410.   StrToFloat function. }
  1411.  
  1412. function TextToFloat(Buffer: PChar; var Value;
  1413.   ValueType: TFloatValue): Boolean;
  1414.  
  1415. { FloatToDecimal converts a floating-point value to a decimal representation
  1416.   that is suited for further formatting. The Value parameter must be a
  1417.   variable of type Extended or Currency, as indicated by the ValueType
  1418.   parameter. For values of type Extended, the Precision parameter specifies
  1419.   the requested number of significant digits in the result--the allowed range
  1420.   is 1..18. For values of type Currency, the Precision parameter is ignored,
  1421.   and the implied precision of the conversion is 19 digits. The Decimals
  1422.   parameter specifies the requested maximum number of digits to the left of
  1423.   the decimal point in the result. Precision and Decimals together control
  1424.   how the result is rounded. To produce a result that always has a given
  1425.   number of significant digits regardless of the magnitude of the number,
  1426.   specify 9999 for the Decimals parameter. The result of the conversion is
  1427.   stored in the specified TFloatRec record as follows:
  1428.  
  1429.   Exponent - Contains the magnitude of the number, i.e. the number of
  1430.   significant digits to the right of the decimal point. The Exponent field
  1431.   is negative if the absolute value of the number is less than one. If the
  1432.   number is a NAN (not-a-number), Exponent is set to -32768. If the number
  1433.   is INF or -INF (positive or negative infinity), Exponent is set to 32767.
  1434.  
  1435.   Negative - True if the number is negative, False if the number is zero
  1436.   or positive.
  1437.  
  1438.   Digits - Contains up to 18 (for type Extended) or 19 (for type Currency)
  1439.   significant digits followed by a null terminator. The implied decimal
  1440.   point (if any) is not stored in Digits. Trailing zeros are removed, and
  1441.   if the resulting number is zero, NAN, or INF, Digits contains nothing but
  1442.   the null terminator. }
  1443.  
  1444. procedure FloatToDecimal(var Result: TFloatRec; const Value;
  1445.   ValueType: TFloatValue; Precision, Decimals: Integer);
  1446.  
  1447. { Date/time support routines }
  1448.  
  1449. function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
  1450.  
  1451. function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
  1452. function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
  1453. function TimeStampToMSecs(const TimeStamp: TTimeStamp): Comp;
  1454.  
  1455. { EncodeDate encodes the given year, month, and day into a TDateTime value.
  1456.   The year must be between 1 and 9999, the month must be between 1 and 12,
  1457.   and the day must be between 1 and N, where N is the number of days in the
  1458.   specified month. If the specified values are not within range, an
  1459.   EConvertError exception is raised. The resulting value is the number of
  1460.   days between 12/30/1899 and the given date. }
  1461.  
  1462. function EncodeDate(Year, Month, Day: Word): TDateTime;
  1463.  
  1464. { EncodeTime encodes the given hour, minute, second, and millisecond into a
  1465.   TDateTime value. The hour must be between 0 and 23, the minute must be
  1466.   between 0 and 59, the second must be between 0 and 59, and the millisecond
  1467.   must be between 0 and 999. If the specified values are not within range, an
  1468.   EConvertError exception is raised. The resulting value is a number between
  1469.   0 (inclusive) and 1 (not inclusive) that indicates the fractional part of
  1470.   a day given by the specified time. The value 0 corresponds to midnight,
  1471.   0.5 corresponds to noon, 0.75 corresponds to 6:00 pm, etc. }
  1472.  
  1473. function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;
  1474.  
  1475. { DecodeDate decodes the integral (date) part of the given TDateTime value
  1476.   into its corresponding year, month, and day. If the given TDateTime value
  1477.   is less than or equal to zero, the year, month, and day return parameters
  1478.   are all set to zero. }
  1479.  
  1480. procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);
  1481.  
  1482. { DecodeTime decodes the fractional (time) part of the given TDateTime value
  1483.   into its corresponding hour, minute, second, and millisecond. }
  1484.  
  1485. procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word);
  1486.  
  1487. { DateTimeToSystemTime converts a date and time from Delphi's TDateTime
  1488.   format into the Win32 API's TSystemTime format. }
  1489.  
  1490. procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
  1491.  
  1492. { SystemTimeToDateTime converts a date and time from the Win32 API's
  1493.   TSystemTime format into Delphi's TDateTime format. }
  1494.  
  1495. function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
  1496.  
  1497. { DayOfWeek returns the day of the week of the given date. The result is an
  1498.   integer between 1 and 7, corresponding to Sunday through Saturday. }
  1499.  
  1500. function DayOfWeek(Date: TDateTime): Integer;
  1501.  
  1502. { Date returns the current date. }
  1503.  
  1504. function Date: TDateTime;
  1505.  
  1506. { Time returns the current time. }
  1507.  
  1508. function Time: TDateTime;
  1509.  
  1510. { Now returns the current date and time, corresponding to Date + Time. }
  1511.  
  1512. function Now: TDateTime;
  1513.  
  1514. { IncMonth returns Date shifted by the specified number of months.
  1515.   NumberOfMonths parameter can be negative, to return a date N months ago.
  1516.   If the input day of month is greater than the last day of the resulting
  1517.   month, the day is set to the last day of the resulting month.
  1518.   Input time of day is copied to the DateTime result.  }
  1519.  
  1520. function IncMonth(const Date: TDateTime; NumberOfMonths: Integer): TDateTime;
  1521.  
  1522. { IsLeapYear determines whether the given year is a leap year. }
  1523.  
  1524. function IsLeapYear(Year: Word): Boolean;
  1525.  
  1526. type
  1527.   PDayTable = ^TDayTable;
  1528.   TDayTable = array[1..12] of Word;
  1529.  
  1530. { The MonthDays array can be used to quickly find the number of
  1531.   days in a month:  MonthDays[IsLeapYear(Y), M]      }
  1532.  
  1533. const
  1534.   MonthDays: array [Boolean] of TDayTable =
  1535.     ((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
  1536.      (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31));
  1537.  
  1538. { DateToStr converts the date part of the given TDateTime value to a string.
  1539.   The conversion uses the format specified by the ShortDateFormat global
  1540.   variable. }
  1541.  
  1542. function DateToStr(Date: TDateTime): string;
  1543.  
  1544. { TimeToStr converts the time part of the given TDateTime value to a string.
  1545.   The conversion uses the format specified by the LongTimeFormat global
  1546.   variable. }
  1547.  
  1548. function TimeToStr(Time: TDateTime): string;
  1549.  
  1550. { DateTimeToStr converts the given date and time to a string. The resulting
  1551.   string consists of a date and time formatted using the ShortDateFormat and
  1552.   LongTimeFormat global variables. Time information is included in the
  1553.   resulting string only if the fractional part of the given date and time
  1554.   value is non-zero. }
  1555.  
  1556. function DateTimeToStr(DateTime: TDateTime): string;
  1557.  
  1558. { StrToDate converts the given string to a date value. The string must
  1559.   consist of two or three numbers, separated by the character defined by
  1560.   the DateSeparator global variable. The order for month, day, and year is
  1561.   determined by the ShortDateFormat global variable--possible combinations
  1562.   are m/d/y, d/m/y, and y/m/d. If the string contains only two numbers, it
  1563.   is interpreted as a date (m/d or d/m) in the current year. Year values
  1564.   between 0 and 99 are assumed to be in the current century. If the given
  1565.   string does not contain a valid date, an EConvertError exception is
  1566.   raised. }
  1567.  
  1568. function StrToDate(const S: string): TDateTime;
  1569.  
  1570. { StrToTime converts the given string to a time value. The string must
  1571.   consist of two or three numbers, separated by the character defined by
  1572.   the TimeSeparator global variable, optionally followed by an AM or PM
  1573.   indicator. The numbers represent hour, minute, and (optionally) second,
  1574.   in that order. If the time is followed by AM or PM, it is assumed to be
  1575.   in 12-hour clock format. If no AM or PM indicator is included, the time
  1576.   is assumed to be in 24-hour clock format. If the given string does not
  1577.   contain a valid time, an EConvertError exception is raised. }
  1578.  
  1579. function StrToTime(const S: string): TDateTime;
  1580.  
  1581. { StrToDateTime converts the given string to a date and time value. The
  1582.   string must contain a date optionally followed by a time. The date and
  1583.   time parts of the string must follow the formats described for the
  1584.   StrToDate and StrToTime functions. }
  1585.  
  1586. function StrToDateTime(const S: string): TDateTime;
  1587.  
  1588. { FormatDateTime formats the date-and-time value given by DateTime using the
  1589.   format given by Format. The following format specifiers are supported:
  1590.  
  1591.   c       Displays the date using the format given by the ShortDateFormat
  1592.           global variable, followed by the time using the format given by
  1593.           the LongTimeFormat global variable. The time is not displayed if
  1594.           the fractional part of the DateTime value is zero.
  1595.  
  1596.   d       Displays the day as a number without a leading zero (1-31).
  1597.  
  1598.   dd      Displays the day as a number with a leading zero (01-31).
  1599.  
  1600.   ddd     Displays the day as an abbreviation (Sun-Sat) using the strings
  1601.           given by the ShortDayNames global variable.
  1602.  
  1603.   dddd    Displays the day as a full name (Sunday-Saturday) using the strings
  1604.           given by the LongDayNames global variable.
  1605.  
  1606.   ddddd   Displays the date using the format given by the ShortDateFormat
  1607.           global variable.
  1608.  
  1609.   dddddd  Displays the date using the format given by the LongDateFormat
  1610.           global variable.
  1611.  
  1612.   g       Displays the period/era as an abbreviation (Japanese and
  1613.           Taiwanese locales only).
  1614.  
  1615.   gg      Displays the period/era as a full name.
  1616.  
  1617.   e       Displays the year in the current period/era as a number without
  1618.           a leading zero (Japanese, Korean and Taiwanese locales only).
  1619.  
  1620.   ee      Displays the year in the current period/era as a number with
  1621.           a leading zero (Japanese, Korean and Taiwanese locales only).
  1622.  
  1623.   m       Displays the month as a number without a leading zero (1-12). If
  1624.           the m specifier immediately follows an h or hh specifier, the
  1625.           minute rather than the month is displayed.
  1626.  
  1627.   mm      Displays the month as a number with a leading zero (01-12). If
  1628.           the mm specifier immediately follows an h or hh specifier, the
  1629.           minute rather than the month is displayed.
  1630.  
  1631.   mmm     Displays the month as an abbreviation (Jan-Dec) using the strings
  1632.           given by the ShortMonthNames global variable.
  1633.  
  1634.   mmmm    Displays the month as a full name (January-December) using the
  1635.           strings given by the LongMonthNames global variable.
  1636.  
  1637.   yy      Displays the year as a two-digit number (00-99).
  1638.  
  1639.   yyyy    Displays the year as a four-digit number (0000-9999).
  1640.  
  1641.   h       Displays the hour without a leading zero (0-23).
  1642.  
  1643.   hh      Displays the hour with a leading zero (00-23).
  1644.  
  1645.   n       Displays the minute without a leading zero (0-59).
  1646.  
  1647.   nn      Displays the minute with a leading zero (00-59).
  1648.  
  1649.   s       Displays the second without a leading zero (0-59).
  1650.  
  1651.   ss      Displays the second with a leading zero (00-59).
  1652.  
  1653.   t       Displays the time using the format given by the ShortTimeFormat
  1654.           global variable.
  1655.  
  1656.   tt      Displays the time using the format given by the LongTimeFormat
  1657.           global variable.
  1658.  
  1659.   am/pm   Uses the 12-hour clock for the preceding h or hh specifier, and
  1660.           displays 'am' for any hour before noon, and 'pm' for any hour
  1661.           after noon. The am/pm specifier can use lower, upper, or mixed
  1662.           case, and the result is displayed accordingly.
  1663.  
  1664.   a/p     Uses the 12-hour clock for the preceding h or hh specifier, and
  1665.           displays 'a' for any hour before noon, and 'p' for any hour after
  1666.           noon. The a/p specifier can use lower, upper, or mixed case, and
  1667.           the result is displayed accordingly.
  1668.  
  1669.   ampm    Uses the 12-hour clock for the preceding h or hh specifier, and
  1670.           displays the contents of the TimeAMString global variable for any
  1671.           hour before noon, and the contents of the TimePMString global
  1672.           variable for any hour after noon.
  1673.  
  1674.   /       Displays the date separator character given by the DateSeparator
  1675.           global variable.
  1676.  
  1677.   :       Displays the time separator character given by the TimeSeparator
  1678.           global variable.
  1679.  
  1680.   'xx'    Characters enclosed in single or double quotes are displayed as-is,
  1681.   "xx"    and do not affect formatting.
  1682.  
  1683.   Format specifiers may be written in upper case as well as in lower case
  1684.   letters--both produce the same result.
  1685.  
  1686.   If the string given by the Format parameter is empty, the date and time
  1687.   value is formatted as if a 'c' format specifier had been given.
  1688.  
  1689.   The following example:
  1690.  
  1691.     S := FormatDateTime('"The meeting is on" dddd, mmmm d, yyyy, ' +
  1692.       '"at" hh:mm AM/PM', StrToDateTime('2/15/95 10:30am'));
  1693.  
  1694.   assigns 'The meeting is on Wednesday, February 15, 1995 at 10:30 AM' to
  1695.   the string variable S. }
  1696.  
  1697. function FormatDateTime(const Format: string; DateTime: TDateTime): string;
  1698.  
  1699. { DateTimeToString converts the date and time value given by DateTime using
  1700.   the format string given by Format into the string variable given by Result.
  1701.   For further details, see the description of the FormatDateTime function. }
  1702.  
  1703. procedure DateTimeToString(var Result: string; const Format: string;
  1704.   DateTime: TDateTime);
  1705.  
  1706. { System error messages }
  1707.  
  1708. function SysErrorMessage(ErrorCode: Integer): string;
  1709.  
  1710. { Initialization file support }
  1711.  
  1712. function GetLocaleStr(Locale, LocaleType: Integer; const Default: string): string;
  1713. function GetLocaleChar(Locale, LocaleType: Integer; Default: Char): Char;
  1714.  
  1715. { GetFormatSettings resets all date and number format variables to their
  1716.   default values. }
  1717.  
  1718. procedure GetFormatSettings;
  1719.  
  1720. { Exception handling routines }
  1721.  
  1722. function ExceptObject: TObject;
  1723. function ExceptAddr: Pointer;
  1724.  
  1725. function ExceptionErrorMessage(ExceptObject: TObject; ExceptAddr: Pointer;
  1726.   Buffer: PChar; Size: Integer): Integer;
  1727.  
  1728. procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer);
  1729.  
  1730. procedure Abort;
  1731.  
  1732. procedure OutOfMemoryError;
  1733.  
  1734. procedure Beep;
  1735.  
  1736. { MBCS functions }
  1737.  
  1738. { LeadBytes is a char set that indicates which char values are lead bytes
  1739.   in multibyte character sets (Japanese, Chinese, etc).
  1740.   This set is always empty for western locales. }
  1741. var
  1742.   LeadBytes: set of Char = [];
  1743.  
  1744. { ByteType indicates what kind of byte exists at the Index'th byte in S.
  1745.   Western locales always return mbSingleByte.  Far East multibyte locales
  1746.   may also return mbLeadByte, indicating the byte is the first in a multibyte
  1747.   character sequence, and mbTrailByte, indicating that the byte is the second
  1748.   in a multibyte character sequence.  Parameters are assumed to be valid. }
  1749.  
  1750. function ByteType(const S: string; Index: Integer): TMbcsByteType;
  1751.  
  1752. { StrByteType works the same as ByteType, but on null-terminated PChar strings }
  1753.  
  1754. function StrByteType(Str: PChar; Index: Cardinal): TMbcsByteType;
  1755.  
  1756. { ByteToCharLen returns the character length of a MBCS string, scanning the
  1757.   string for up to MaxLen bytes.  In multibyte character sets, the number of
  1758.   characters in a string may be less than the number of bytes.  }
  1759.  
  1760. function ByteToCharLen(const S: string; MaxLen: Integer): Integer;
  1761.  
  1762. { CharToByteLen returns the byte length of a MBCS string, scanning the string
  1763.   for up to MaxLen characters. }
  1764.  
  1765. function CharToByteLen(const S: string; MaxLen: Integer): Integer;
  1766.  
  1767. { ByteToCharIndex returns the 1-based character index of the Index'th byte in
  1768.   a MBCS string.  Returns zero if Index is out of range:
  1769.   (Index <= 0) or (Index > Length(S)) }
  1770.  
  1771. function ByteToCharIndex(const S: string; Index: Integer): Integer;
  1772.  
  1773. { CharToByteIndex returns the 1-based byte index of the Index'th character
  1774.   in a MBCS string.  Returns zero if Index or Result are out of range:
  1775.   (Index <= 0) or (Index > Length(S)) or (Result would be > Length(S)) }
  1776.  
  1777. function CharToByteIndex(const S: string; Index: Integer): Integer;
  1778.  
  1779. { IsPathDelimiter returns True if the character at byte S[Index]
  1780.   is '\', and it is not a MBCS lead or trail byte. }
  1781.  
  1782. function IsPathDelimiter(const S: string; Index: Integer): Boolean;
  1783.  
  1784. { IsDelimiter returns True if the character at byte S[Index] matches any
  1785.   character in the Delimiters string, and the character is not a MBCS lead or
  1786.   trail byte.  S may contain multibyte characters; Delimiters must contain
  1787.   only single byte characters. }
  1788.  
  1789. function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean;
  1790.  
  1791. { LastDelimiter returns the byte index in S of the rightmost whole
  1792.   character that matches any character in Delimiters (except null (#0)).
  1793.   S may contain multibyte characters; Delimiters must contain only single
  1794.   byte non-null characters.
  1795.   Example: LastDelimiter('\.:', 'c:\filename.ext') returns 12. }
  1796.  
  1797. function LastDelimiter(const Delimiters, S: string): Integer;
  1798.  
  1799. { AnsiCompareFileName supports DOS file name comparison idiosyncracies
  1800.   in Far East locales (Zenkaku).  In non-MBCS locales, AnsiCompareFileName
  1801.   is identical to AnsiCompareText.  For general purpose file name comparisions,
  1802.   you should use this function instead of AnsiCompareText. }
  1803.  
  1804. function AnsiCompareFileName(const S1, S2: string): Integer;
  1805.  
  1806. { AnsiLowerCaseFileName supports lowercase conversion idiosyncracies of
  1807.   DOS file names in Far East locales (Zenkaku).  In non-MBCS locales,
  1808.   AnsiLowerCaseFileName is identical to AnsiLowerCase. }
  1809.  
  1810. function AnsiLowerCaseFileName(const S: string): string;
  1811.  
  1812. { AnsiUpperCaseFileName supports uppercase conversion idiosyncracies of
  1813.   DOS file names in Far East locales (Zenkaku).  In non-MBCS locales,
  1814.   AnsiUpperCaseFileName is identical to AnsiUpperCase. }
  1815.  
  1816. function AnsiUpperCaseFileName(const S: string): string;
  1817.  
  1818. { AnsiPos:  Same as Pos but supports MBCS strings }
  1819.  
  1820. function AnsiPos(const Substr, S: string): Integer;
  1821.  
  1822. { AnsiStrPos: Same as StrPos but supports MBCS strings }
  1823.  
  1824. function AnsiStrPos(Str, SubStr: PChar): PChar;
  1825.  
  1826. { AnsiStrRScan: Same as StrRScan but supports MBCS strings }
  1827.  
  1828. function AnsiStrRScan(Str: PChar; Chr: Char): PChar;
  1829.  
  1830. { AnsiStrScan: Same as StrScan but supports MBCS strings }
  1831.  
  1832. function AnsiStrScan(Str: PChar; Chr: Char): PChar;
  1833.  
  1834. { StringReplace replaces occurances of <oldpattern> with <newpattern> in a
  1835.   given string.  Assumes the string may contain Multibyte characters }
  1836.  
  1837. type
  1838.   TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);
  1839.  
  1840. function StringReplace(const S, OldPattern, NewPattern: string;
  1841.   Flags: TReplaceFlags): string;
  1842.  
  1843. { WrapText will scan a string for BreakChars and insert the BreakStr at the
  1844.   last BreakChar position before MaxCol.  Will not insert a break into an
  1845.   embedded quoted string (both ''' and '"' supported) }
  1846.  
  1847. function WrapText(const Line, BreakStr: string; BreakChars: TSysCharSet;
  1848.   MaxCol: Integer): string;
  1849.  
  1850. { FindCmdLineSwitch determines whether the string in the Switch parameter
  1851.   was passed as a command line argument to the application.  SwitchChars
  1852.   identifies valid argument-delimiter characters (i.e., "-" and "/" are
  1853.   common delimiters). The IgnoreCase paramter controls whether a
  1854.   case-sensistive or case-insensitive search is performed. }
  1855.  
  1856. function FindCmdLineSwitch(const Switch: string; SwitchChars: TSysCharSet;
  1857.   IgnoreCase: Boolean): Boolean;
  1858.  
  1859. { Package support routines }
  1860.  
  1861. { Package Info flags }
  1862.  
  1863. const
  1864.   pfNeverBuild = $00000001;
  1865.   pfDesignOnly = $00000002;
  1866.   pfRunOnly = $00000004;
  1867.   pfModuleTypeMask = $C0000000;
  1868.   pfExeModule = $00000000;
  1869.   pfPackageModule = $40000000;
  1870.   pfLibraryModule = $80000000;
  1871.  
  1872. { Unit info flags }
  1873.  
  1874. const
  1875.   ufMainUnit = $01;
  1876.   ufPackageUnit = $02;
  1877.   ufWeakUnit = $04;
  1878.   ufOrgWeakUnit = $08;
  1879.   ufImplicitUnit = $10;
  1880.  
  1881.   ufWeakPackageUnit = ufPackageUnit or ufWeakUnit;
  1882.  
  1883. { Procedure type of the callback given to GetPackageInfo.  Name is the actual
  1884.   name of the package element.  If IsUnit is True then Name is the name of
  1885.   a contained unit; a required package if False.  Param is the value passed
  1886.   to GetPackageInfo }
  1887.  
  1888. type
  1889.   TNameType = (ntContainsUnit, ntRequiresPackage);
  1890.  
  1891.   TPackageInfoProc = procedure (const Name: string; NameType: TNameType; Flags: Byte; Param: Pointer);
  1892.  
  1893. { LoadPackage loads a given package DLL, checks for duplicate units and
  1894.   calls the initialization blocks of all the contained units }
  1895.  
  1896. function LoadPackage(const Name: string): HMODULE;
  1897.  
  1898. { UnloadPackage does the opposite of LoadPackage by calling the finalization
  1899.   blocks of all contained units, then unloading the package DLL }
  1900.  
  1901. procedure UnloadPackage(Module: HMODULE);
  1902.  
  1903. { GetPackageInfo accesses the given package's info table and enumerates
  1904.   all the contained units and required packages }
  1905.  
  1906. procedure GetPackageInfo(Module: HMODULE; Param: Pointer; var Flags: Integer;
  1907.   InfoProc: TPackageInfoProc);
  1908.  
  1909. { GetPackageDescription loads the description resource from the package
  1910.   library. If the description resource does not exist,
  1911.   an empty string is returned. }
  1912. function GetPackageDescription(ModuleName: PChar): string;
  1913.  
  1914. { InitializePackage Validates and initializes the given package DLL }
  1915.  
  1916. procedure InitializePackage(Module: HMODULE);
  1917.  
  1918. { FinalizePackage finalizes the given package DLL }
  1919.  
  1920. procedure FinalizePackage(Module: HMODULE);
  1921.  
  1922. { RaiseLastWin32Error calls the GetLastError API to retrieve the code for }
  1923. { the last occuring Win32 error.  If GetLastError returns an error code,  }
  1924. { RaiseLastWin32Error then raises an exception with the error code and    }
  1925. { message associated with with error. }
  1926.  
  1927. procedure RaiseLastWin32Error;
  1928.  
  1929. { Win32Check is used to check the return value of a Win32 API function     }
  1930. { which returns a BOOL to indicate success.  If the Win32 API function     }
  1931. { returns False (indicating failure), Win32Check calls RaiseLastWin32Error }
  1932. { to raise an exception.  If the Win32 API function returns True,          }
  1933. { Win32Check returns True. }
  1934.  
  1935. function Win32Check(RetVal: BOOL): BOOL;
  1936.  
  1937. { Termination procedure support }
  1938.  
  1939. type
  1940.   TTerminateProc = function: Boolean;
  1941.  
  1942. { Call AddTerminateProc to add a terminate procedure to the system list of }
  1943. { termination procedures.  Delphi will call all of the function in the     }
  1944. { termination procedure list before an application terminates.  The user-  }
  1945. { defined TermProc function should return True if the application can      }
  1946. { safely terminate or False if the application cannot safely terminate.    }
  1947. { If one of the functions in the termination procedure list returns False, }
  1948. { the application will not terminate. }
  1949.  
  1950. procedure AddTerminateProc(TermProc: TTerminateProc);
  1951.  
  1952. { CallTerminateProcs is called by VCL when an application is about to }
  1953. { terminate.  It returns True only if all of the functions in the     }
  1954. { system's terminate procedure list return True.  This function is    }
  1955. { intended only to be called by Delphi, and it should not be called   }
  1956. { directly. }
  1957.  
  1958. function CallTerminateProcs: Boolean;
  1959.  
  1960. function GDAL: Longint;
  1961. procedure RCS;
  1962. procedure RPR;
  1963.  
  1964.  
  1965. { HexDisplayPrefix contains the prefix to display on hexadecimal
  1966.   values - '$' for Pascal syntax, '0x' for C++ syntax.  This is
  1967.   for display only - this does not affect the string-to-integer
  1968.   conversion routines. }
  1969. var
  1970.   HexDisplayPrefix: string = '$';
  1971.  
  1972. implementation
  1973.